using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using CGMSharp.Configuration;

namespace CGMSharp.Types
{
    class CCO : AbstractType
    {
        private int val;

        public CCO(DataTypeConfiguration Configuration)
        {
            this.Configuration = Configuration;
        }

        public CCO(DataTypeConfiguration Configuration, Stream s)
        {
            this.Configuration = Configuration;
            ReadFromStream(s);
        }

        public override int ReadFromStream(System.IO.Stream s)
        {
            val = BinaryUtil.ReadUI(s, Configuration.DirectColorPrecision);
            return Configuration.DirectColorPrecision;
        }

        public override int WriteToStream(System.IO.Stream s)
        {
            BinaryUtil.WriteUI(s, Configuration.DirectColorPrecision, val);
            return Configuration.DirectColorPrecision;
        }

        public override int Octets()
        {
            return Configuration.DirectColorPrecision / 8;
        }

        public override string ToString()
        {
            return "CCO";
        }

        public int Val
        {
            get { return val; }
            set { val = value; }
        }
    }
}